<%@ page language="java" contentType="text/html;charset=UTF-8" %><%@ include file="../../inc/global.jsp" 
%>
<!doctype html>
<html>
<head>
<title>${adminGlobalConfig.name}</title>
<%@include file="../head.jsp" %>
<style type="text/css">
#ajaxData ul {margin:21px 11px 0px 11px;}
#ajaxData ul li {display:inline-block; padding:7px 15px; float:left; background:#d0d0d0; margin:7px;
	cursor:pointer; color:#666}
#ajaxData div {display:block; text-align:center; width:90%;}
#ajaxData div:after {
	content: '.';
	display: block;
	clear: both;
	visibility: hidden;
	height: 0;
}
#ajaxData ul li.slt, #ajaxData ul li.hover{background:#ff6600; color:#fff;}
</style>
<script type="text/javascript">
function AddTown() {
	var _this = this;
	var dt, bg;
	function showTip(o, content) {
		$(o).poshytip({
			content: content,
			showOn: 'none',
			showTimeout: '1',
			className: 'tip-yellow',
			alignTo: 'target',
			alignX: 'top',
			alignY: 'bottom',
			offsetX: -160,
			offsetY: 5
		}).poshytip('show');
	};
	function hideTip() {
		aju.removeAll([$('.tip-yellow')]);
	};
	this.hide = function() {
		aju.removeAll([dt,bg]);
		$('#ajaxClose').remove();
	};
	this.init = function() {
		$('#addTown').click(function(){
			hideTip();
			_this.showForm();
		});
		$('input[name=button]').click(function(){
			var name = $('#name').val();
			var content = $('#content').val();
			var townIds = $('#townIds').val();
			var endTime = $('#endTime').val();
			if(name==undefined || name.length==0) {
				showTip($('#name'), '任务名称不能为空！');
				$('#name').focus();
				return ;
			}
			else if(content==undefined || content.length==0) {
				showTip($('#content'), '任务内容不能为空！');
				$('#content').focus();
				return ;
			}
			else if(townIds==undefined || townIds.length==0) {
				showTip($('#addTown'), '请添加发送目标所在地区！');
				return ;
			}
			$(this).val('正在保存任务，请稍候哦...').attr('disabled', 'disabled');
			var url='/a/ajax/customer/msgJobs/save';
			$.ajax({
				type:'POST'
				, url:url
				, data:{name:name,content:content,townIds:townIds,endTime:endTime}
				, success:function(data){
					window.location='/a/customer/msgJobs';
				}
				,error:function(){
					alert('系统错误，请联系管理员！');
					$(this).val('确定保存').removeAttr('disabled');
				}
			});			
		});
		$('input[type=text]').keydown(function(){
			hideTip();
		});
		$('textarea').keydown(function(){
			hideTip();
		});
	};
	this.save = function() {
		
	};
	this.showForm = function() {
		bg = aju.ajaxBg(function() {
			aju.setOffsetDown(20);
			aju.setOffsetRight(10);
			var url = '/a/ajax/customer/townSelector?r=' + new Date();
			$.get(url, function(data){
					dt = aju.ajaxData().css('width','980');
					dt.html(data);
					aju.positionCenter(dt);
					aju.ajaxClose(dt).click(function(){
						_this.hide();
					});
					var newval;
					dt.find('li').each(function(){
						$(this).mouseover(function(){
							$(this).addClass('hover');
						}).mouseout(function(){
							$(this).removeClass('hover');
						}).click(function(){
							var id = $(this).attr('id');
							var dftval = $('#_townIds').val();
							if(dftval==undefined) {
								newval = id+",";
								$(this).addClass('slt');
							} else if(dftval.indexOf(id)!=-1){
								newval = $('#_townIds').val().replace(id+",",'')
								$(this).removeClass('slt');
							} else {
								$(this).addClass('slt');
								newval = dftval + id+",";
							}
							$('#_townIds').val(newval);
						});
						dt.find('input[name=button]').click(function(){
							$('#townIds').val(newval);
							var names='';
							dt.find('li.slt').each(function(){
								names+=$(this).html() + ", ";
							});
							$('#addTown').html(names + '  <strong>[添加修改地区]</strong>');
							_this.hide();
						});
						var _val = $('#townIds').val();
						if(_val!=undefined) {
							$('#_townIds').val(_val);
							var vals = _val.split(',');
							for(var i=0; i<vals.length;  i++){
								var v = vals[i];
								$('#'+v).addClass('slt');
							}
						}
					});
			});
		});
		$('body').keydown(function(event){
			switch(event.keyCode) {
			case KEY.ESC :
				_this.hide();
			}
		});
	};
}
var addTown = new AddTown();
$(function(){
	$( "#endTime" ).datepicker({
		dateFormat:'yy-mm-dd'
	});
	addTown.init();
});
</script>
</head>
<body>
<div class="wrapper">
<%@include file="../header.jsp" %>
<div class="body">
<div class="form">
<div class="listnav">
</div>
<table>
<tbody>
<tr>
<th>任务名称/代号</th>
<td><input type="text" id="name" name="name" value="" /></td>
</tr>
<tr>
<th>发送内容</th>
<td><textarea id="content" name="content"></textarea></td>
</tr>
<tr>
<th>发送方式</th>
<td>
<label for="type_0"><input type="checkbox" id="type_0" name="type" value="0" checked="checked" disabled/>手机短信</label>
</td>
</tr>
<tr>
<th>发送目标</th>
<td>
<a href="###" id="addTown">添加地区</A>
<input type="hidden" id="townIds" name="townIds"/>
</td>
</tr>
<tr>
<th>结束日期</th>
<td>
<input type="text" id="endTime" name="endTime" value="${endDate}" class=hasDatepicker"/>
<br/>
超过此日期后消息将不在发送
</td>
</tr>
<tr>
<th></th>
<td>
<input type="button" name="button" value="<fmt:message key="message.save.sure"/>" />
</td>
</tr>
</tbody>
</table>
</div>
<div class="sidebarMenu">
<ul>
<li><a href="/a/customer/msgJobs/create">新建群发任务</a></li>
<li><a href="/a/customer/msgJobs">返回全部任务</a></li>
</ul>
</div>
<div class="sidebar">
<div class="prop-item">
</div>
</div>
<!--  -->
</div>
</div>
</body>
</html>